﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using log4net;
using System.Diagnostics.Eventing;


namespace ZuggerWpf
{
    class PMSUtil
    {
        //private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public static bool GetToken(string url, string accout, string password, ref string sessionname){
            bool isSuccess = false;

            JObject root = new JObject{
                    { "account", "lutianming"},
                    { "password", "Lu123456"}
                };

            JObject res = WebTools.Post(url, root, null);
            if (res.Property("token") != null)
            {
                isSuccess = true;
                sessionname = (string)res["token"];
            }
            return isSuccess;
        }

        public static bool DoLogin(string url, string token, ref string[] products)
        {
            bool isSuccess = false;

            JObject header = new JObject { { "Token", token } };
            JObject res = WebTools.Get(url, header);
            if (res.Property("profile") != null)
            {
                isSuccess = true;
                string product = (string)res["profile"]["view"]["products"];
                products = product.Split(',');
            }
            return isSuccess;
        }
    }
}
